package online.foxnull2.foxmall.product.web;

import online.foxnull2.foxmall.product.entity.CategoryEntity;
import online.foxnull2.foxmall.product.service.CategoryService;
import online.foxnull2.foxmall.product.vo.Catalog2Vo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    private CategoryService categoryService;

    @Autowired
    public void setCategoryService(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    @GetMapping({"/", "/index", "/index.html"})
    public String index(Model model) {

        List<CategoryEntity> categoryEntityList = categoryService.getLv1Category();
        model.addAttribute("categoryEntityList", categoryEntityList);

        return "index";
    }

    @ResponseBody
    @GetMapping("/index/json/catalog")
    public Map<String, List<Catalog2Vo>> jsonCatalog() {
        return categoryService.getJsonCatalog();
    }

}
